<?php 
	session_start();
	include_once("./head.php");
	include_once("./commonality.php");
	date_default_timezone_set('PRC');
 	 $b=date("Ymd");
 	 $c=rand(10000,99);
 	 $ane=$b.$c;
 	 $a=date('Y-m-d h:i:s',time());
 	 $set="select * from product";
	$res=mysql_query($set);
	while($list=mysql_fetch_assoc($res)){
	$sets[]=$list;
	}
	foreach ($sets as $value){ 
		foreach ($_SESSION['cart'] as $v) {
			if($value['pid']==$v['pid']){ 
				$zongjia+=$value['price']*$v['num'];
			}
		}			
	}
	//获取数据	
	$addr_id=$_POST['addr_id'];
	$uid=$_SESSION['uid'];

	foreach ($_SESSION['cart'] as $value) {
			$pid=$value['pid'];
			$id[]=$pid;
			$size=$value['size'];
			$color=$value['color'];
			$mql="insert into goods(gsize,gcolor,order_sn,pid,uid)value('$size','$color','$ane','$pid','$uid')";
			mysql_query($mql);
			$fgd=mysql_affected_rows();
	}
	//组装sql语句
	$id=implode("-",$id);
	$sql="insert into ts_order(addr_id,uid,goods_id,subtotal,order_time,order_sn)values('$addr_id','$uid','$id','$zongjia','$a','$ane')";
	mysql_query($sql);
	$sal=mysql_affected_rows();
	if($fgd>0 && $sal>0){
		echo "<script>alert('操作成功');</script>";
	}else{
		//echo "<script>alert('操作失败');';</script>";
	}

 ?>
 <!DOCTYPE html>
 <html>
 <head>
 	<title></title>
 </head>
 <style type="text/css">
 .c1{
		width:10%;
		height:40px;
		/*border:1px solid red;*/
		margin-left:60px;
		font-size:18px;

	}
	table{
		width:85%;
		height:280px;
		border:1px solid #AAAAB4;
		margin-left:85px;
	}
	.d1{		
		width:100px;
		height:30px;
		background:#FA9300;
		line-height:30px;
		display:inline-block;
		line-height:30px;
		text-align:center;
		color:white;
		font-size:18px;
		border-radius:5px;
		margin-left:430px;
	}		
		.hehe{
		width:100px;
		height:30px;
		background:#57abff;
		line-height:30px;
		display:inline-block;
		line-height:30px;
		text-align:center;
		color:white;
		font-size:18px;
		border-radius:5px;
		margin-left:80px;
		}

</style>
 <body>
 	<span class="c1">当前所在：商城>完成订单</span><hr color="#d1d1d1"><br><br>
 	<!-- <div class="ding"> -->
 		<table border=0px solid #AAAAB4; align="center" >
 		<tr align="center">
 		<td>
			<img src="./img/9.png">
		</td>
		</tr>
		<tr align="center">
		<td>
			您的订单号是：<?= $ane ?>
			</td>
		</tr>
		<tr align="center">
			<td>下单时间：<?= $a ?></td>
		</tr>
		<tr align="center">	
			<td>订单总额：<?= $zongjia ?></td>
		</tr>
		<tr>
		<td>
		<a href="order_list.php"><div class="d1">订单列表</div></a>
		<a href="index.php"><div class="hehe">返回首页</div></a>
		</td>
		</tr>
		</table>
 </body>
 </html>
 <?php 
 	unset($_SESSION['cart']);
  ?>